package com.taskschecker;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.view.View;
import android.widget.LinearLayout.LayoutParams;

public class CalendarDayHeader extends View {

	private final static int HEADER_TEXT_SIZE = 22;
	private Paint pt = new Paint();
	private RectF rect = new RectF();
	private int iWeekDay = -1;

	public CalendarDayHeader(Context context, int iWidth, int iHeight) {
		super(context);
		setLayoutParams(new LayoutParams(iWidth, iHeight));
	}

	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);

		rect.set(0, 0, this.getWidth(), this.getHeight());
		rect.inset(1, 1);

		drawDayHeader(canvas);
	}

	private void drawDayHeader(Canvas canvas) {
		pt.setColor(TasksCheckerActivity.calendar_WeekBgColor);
		canvas.drawRect(rect, pt);

		final String sDayName = CalendarUtils.getWeekDayName(iWeekDay);

		pt.setTypeface(null);
		pt.setTextSize(HEADER_TEXT_SIZE);
		pt.setAntiAlias(true);
		pt.setFakeBoldText(true);
		if ("SUN".equals(sDayName) || "SAT".equals(sDayName))
			pt.setColor(TasksCheckerActivity.calendarHolidayFontColor);
		else
			pt.setColor(TasksCheckerActivity.calendar_WeekFontColor);

		final int iPosX = (int)rect.left + (int)rect.width()/2 - (int)pt.measureText(sDayName)/2;
		final int iPosY = (int)(this.getHeight() - (this.getHeight() - getTextHeight()) / 2 - pt.getFontMetrics().bottom);

		canvas.drawText(sDayName, iPosX, iPosY, pt);
	}

	private int getTextHeight() {
		return (int) (-pt.ascent() + pt.descent());
	}

	public void setData(int iWeekDay) {
		this.iWeekDay = iWeekDay;
	}

}
